package com.jack.topvision.tvcamera2;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;

import com.topvision.jack.camerasdk2.camera.callback.OnVideoListener;
import com.topvision.jack.camerasdk2.camera.commom.CameraConstants;
import com.topvision.jack.camerasdk2.camera.view.TvVideoView;

import java.io.File;
import java.util.ArrayList;


/**
 * 预览视频demo
 * 创建时间:2017/12/26
 * 作者 jack
 * 描述
*/
public class ShowVideoActivity extends Activity implements OnVideoListener,View.OnClickListener {

    TvVideoView tvVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_video_test);
        initView();
        Log.e("ShowVideoActivity", "onCreate");
    }

    private void initView() {
        tvVideoView = (TvVideoView) findViewById(R.id.tvVideoView);
        tvVideoView.setOnVideoListener(this);
        //轮播
        tvVideoView.setCarousel(true);
        ArrayList<String> list2 = new ArrayList<>();
        String video1 = Environment.getExternalStorageDirectory().getPath() + File.separator + "topvisionvideo/a.mp4";
        String video2 = Environment.getExternalStorageDirectory().getPath() + File.separator + "topvisionvideo/b.mp4";
        String video3 = Environment.getExternalStorageDirectory().getPath() + File.separator + "topvisionvideo/c.mp4";
        list2.add(video1);
        list2.add(video2);
        list2.add(video3);
        tvVideoView.setVideos(list2);
        tvVideoView.playVideo();

       findViewById(R.id.pauseTestBtn).setOnClickListener(this);
       findViewById(R.id.resumeTestBtn).setOnClickListener(this);
       findViewById(R.id.nextTestBtn).setOnClickListener(this);
       findViewById(R.id.previousTestBtn).setOnClickListener(this);

    }


    @Override
    public void videoError(String errorMsg) {
        Log.e(CameraConstants.TAG,errorMsg);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //继续播放视频
        tvVideoView.resumeVideo();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //暂停播放视频
        tvVideoView.pauseVideo();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.pauseTestBtn) {
            tvVideoView.pauseVideo();
        } else if (view.getId() == R.id.resumeTestBtn) {
            tvVideoView.resumeVideo();
        } else if (view.getId() == R.id.previousTestBtn) {
            tvVideoView.playPreviousVideo();
        } else if (view.getId() == R.id.nextTestBtn) {
            tvVideoView.playNextVideo();
        }
    }
}
